package com.shujia.spark.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo4UsePersonModel {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession
      .builder()
      .master("local")
      .appName("point")
      .config("spark.sql.shuffle.partitions", 1)
      .getOrCreate()

    import spark.implicits._
    import org.apache.spark.sql.functions._

    /**
     * 加载保存的模型
     *
     */

    val model: LogisticRegressionModel = LogisticRegressionModel.load("data/person_model")

    /**
     * 使用模型进行预测
     * transform: 批量预测
     * predict: 单条预测
     */

    /**
     * 1 1:4.9 2:3.9 3:3.0 4:131.0 5:79.8 6:63.7 7:77
     * 0 1:4.2 2:3.0 3:2.4 4:97.3 5:57.7 6:58.5 7:89
     */
    val y1: Double = model.predict(Vectors.dense(4.9, 3.9, 3.0, 131.0, 79.8, 63.7, 77))
    println(y1)

    val y2: Double = model.predict(Vectors.dense(4.9, 3.9, 3.0, 131.0, 79.8, 63.7, 77))
    println(y2)
  }

}
